﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection conn = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Employee"] == null)
        {
            Response.Redirect("~/Login.aspx");
        }
        else
        {
            conn = Database.GetConnection();
            GetEmployee();
        }
    }
    public void GetEmployee()
    {
        DataTable dtEmployee = (DataTable)Session["Employee"];
        lblName.Text = dtEmployee.Rows[0][3].ToString();
        lblEmail.Text = dtEmployee.Rows[0][4].ToString();
        lblAddress.Text = dtEmployee.Rows[0][5].ToString();
        lblRole.Text = GetRole();
        lblDepartment.Text = GetDepartment();

    }
    public string GetRole()
    {
        DataTable dtEmployee = (DataTable)Session["Employee"];
        string idrole = dtEmployee.Rows[0][6].ToString();
        SqlDataAdapter adapter = new SqlDataAdapter("select * from Roles where Roles_ID = "+idrole+"", conn);
        DataTable dtrole = new DataTable();
        adapter.Fill(dtrole);
        return dtrole.Rows[0][1].ToString();
    }
    public string GetDepartment()
    {
        DataTable dtEmployee = (DataTable)Session["Employee"];
        string iddepartment = dtEmployee.Rows[0][7].ToString();
        SqlDataAdapter adapter = new SqlDataAdapter("select * from Department where D_ID = "+iddepartment+"", conn);
        DataTable dtdepartment = new DataTable();
        adapter.Fill(dtdepartment);
        return dtdepartment.Rows[0][1].ToString();
    }
    protected void lbLogout_Click(object sender, EventArgs e)
    {
        Session["Emoloyee"] = null;
        Response.Redirect("~/Login.aspx");
    }
}